﻿using System;
using System.Collections.Generic;
using TeamCommunitySolution.Domain.DataLayer.Leagues;

namespace TeamCommunitySolution.Domain.DataLayer.Base
{
    /// <summary>
    /// Team Object.
    /// </summary>
    [Serializable]
    public class Team
    {
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id of the team.</value>
        public virtual string Id { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name of the team.</value>
        public virtual string Name { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets or sets the date founded.
        /// </summary>
        /// <value>The date founded.</value>
        public virtual DateTime DateFounded { get; set; }

        /// <summary>
        /// Gets or sets the member list.
        /// </summary>
        /// <value>The member list.</value>
        public virtual IList<SystemUser> MemberList { get; set; }

        /// <summary>
        /// Gets or sets the league list.
        /// </summary>
        /// <value>The league list.</value>
        public virtual IList<League> LeagueList { get; set; }

        /// <summary>
        /// Gets or sets the owner.
        /// </summary>
        /// <value>The owner.</value>
        public virtual SystemUser Owner { get; set; }

        /// <summary>
        /// Gets the member count.
        /// </summary>
        /// <value>The member count.</value>
        public virtual int MemberCount
        {
            get { return this.MemberList.Count; }
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            if (!(obj is Team))
            {
                return false;
            }

            Team other = obj as Team;

            return other.Id.Equals(this.Id);
        }
    }
}
